package com.google.com.coma.tester;

import com.google.code.coma.domain.Computer;
import com.google.code.coma.domain.LifeCycleStep;
import com.google.code.coma.domain.Part;
import org.apache.log4j.Logger;

/**
 */
public class DefectTester implements Tester{
	private static final Logger log = Logger.getLogger(DefectTester.class);

	@Override
	public void testComputer(Computer computer, String workerId) {
		boolean isVerified = true;

		for (Part part : computer.getParts()) {
			isVerified = isVerified && !part.isBroken();
		}

		if (log.isInfoEnabled()) {
			if (isVerified) {
				log.info("Computer " + computer + " verified!");
			} else {
				log.info("Computer " + computer + " is broken, rejecting!");
			}
		}
		computer.changeState(isVerified ? LifeCycleStep.VERIFIED : LifeCycleStep.REJECTED, workerId);

	}
}
